// pages/user/index.js
Page({
  data: {
    user_info:{},
    // 被收藏的商品的数量
    collectNums:0
  },
  onShow(){
    const user_info=wx.getStorageSync("user_info");
    const collect=wx.getStorageSync("collect")||[];
      
    this.setData({
      user_info: user_info,
      collectNums:collect.length
    });
      
  },

  handleLogin() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },

  handleInfo() {
    const user_info = wx.getStorageSync('user_info');
    if (user_info) {
      wx.navigateTo({
        url: '/pages/info/info',
      })
    } else {
      wx.showModal({
        title: '您未登录',
        content: '是否跳转到登录界面？',
        success(res){
          if(res.confirm) {
            wx.navigateTo({
              url: '/pages/login/login'
            })
          }
        }
      })
    }
  },

  handleAbout() {
    wx.navigateTo({
      url: '/pages/about/about',
    })
  },

  handleLogout() {
    var that = this;
    wx.showModal({
      title: "登出？",
      content: "您确定要退出登录吗？",
      success (res) {
        if (res.confirm) {
          wx.removeStorageSync('user_info');
          wx.removeStorageSync('bookmarks');
          wx.reLaunch({
            url: '/pages/user/user',
          })
        }
      }
    })
  }
})